package com.zhongxi.guoyuan.adapter.coinShop;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.entity.coinStore.CoinStoreData;
import com.zhongxi.guoyuan.url.Url;

import java.util.List;

/**
 * Created by Administrator on 2016/12/4.
 */

public class CoinStoreAdapter extends BaseAdapter {

    private LayoutInflater mLayoutInflater;
    private List<CoinStoreData> list;
    private Context context;
    public CoinStoreAdapter(Context context, List<CoinStoreData> data) {
        this.mLayoutInflater = LayoutInflater.from(context);
        this.list = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = mLayoutInflater.inflate(R.layout.item_coin_store, parent, false);
            holder.ivImg = (ImageView) convertView.findViewById(R.id.ivImg);
            holder.tvName = (TextView) convertView.findViewById(R.id.tvName);
            holder.tvDesc = (TextView) convertView.findViewById(R.id.tvDesc);
            holder.tvView = (TextView) convertView.findViewById(R.id.tvView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        if(null!=list.get(position)&&!"".equals(list.get(position))){
            CoinStoreData data = list.get(position);
            if(null!=data.getThumbnail()&&!"".equals(data.getThumbnail())){
//                ImageLoader.getInstance().displayImage(Url.IMG_URL+data.getThumbnail(), holder.ivImg, CommonTool.getOptions(R.mipmap.iv_eg));
                Glide.with(context).load(Url.IMG_URL+data.getThumbnail()).placeholder(R.mipmap.iv_loading).into(holder.ivImg);
            }
            if(null!=data.getName()&&!"".equals(data.getName())){
                holder.tvName.setText(data.getName());
            }else{
                holder.tvName.setText("");
            }
            if(null!=data.getSubject()&&!"".equals(data.getSubject())){
                holder.tvDesc.setText(data.getSubject());
            }else{
                holder.tvDesc.setText("");
            }
            if(null!=data.getViewnum()&&!"".equals(data.getViewnum())){
                holder.tvView.setText(data.getViewnum());
            }else{
                holder.tvView.setText("*");
            }
        }
        return convertView;
    }

    class ViewHolder{
        private ImageView ivImg;
        private TextView tvName;
        private TextView tvDesc;
        private TextView tvView;
    }
}
